<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('南昌市临空经济区重大重点项目')" />
    <th:block th:include="include :: datetimepicker-css" />
	<th:block th:include="include :: footer" />
	<style>
		.preview img[src] {width: 70px;height: 70px;margin-left: 40px;}
		.redDot {position: absolute;background: #f94242;width:2em;height:2em;line-height:2em;
    			text-align: center;z-index: 10;color: #fff;border-radius: 50%;left:5px;top: -5px;}
    	#popup {display: none;border-bottom: 0;}
		.tab-content{height: calc(100vh - 80px);overflow: auto;}
	</style>
	<script th:inline="javascript">
	  var projectLists = [[${@project.getProject()}]];
      var costType = [[${@dict.getType('sys_cost_type')}]];
      var costState = [[${@dict.getType('sys_cost_state')}]];
      var affairFlag = [[${@dict.getType('affairFlag')}]];
       function showObjectLabel(datas,value,key,name) {
          $.each(datas, function(index, dict) {
              if ( eval("dict."+key+" == ('' + value)")) {
                 document.write(eval("dict."+name));
              }
          });
          document.write('');
      }
     var urgentDescribe=[];
     
     function oldList(pName){
     	layer.open({
     		type: 2,
     		title:'项目进程:<strong>' +pName+'</strong>',
     		area: ['90%', '90%'],
     		content: ctx +'system/project/oldList/'+pName
     	});
     }
	</script>
</head>
<body class="gray-bg">
	<div class="panel-body" id="popup">
		<div class="col-sm-4">
    		<div id='urgentDescribeList'></div>  
    	</div>
    </div> 
    <div class="wrapper wrapper-content animated fadeIn">
    
   <div class="row"> 
         <div class="col-sm-6">
                <div class="tabs-container">
                	<div class="redDot" id="urgentDescribe"></div>
                    <ul class="nav nav-tabs">
                        <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">项目</a>
                        </li>
                        <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">费用</a>
                        </li>
                        <li class=""><a data-toggle="tab" href="#tab-3" aria-expanded="false">事务</a>
                        </li>
                        <li class=""><a data-toggle="tab" href="#tab-4" aria-expanded="false">批示</a>
                        </li>
                    </ul>
                     <script> 
                     var projectWork = [];
                     var zhichu = 0;
                     var nzhichu = 0;
                     </script>
                    <div class="tab-content">
                        <div id="tab-1" class="tab-pane active">
                            <div class="panel-body">
								 <div class="panel panel-primary" th:each="project : ${@project.getProjectInfo()}">
	                                    <div class="panel-heading"><strong>[(${project.project.projectName})]</strong><i class="fa fa-bars" th:id="'PC'+${project.project.projectId}" style="float: right;"> </i></div>
	                                    <div class="panel-body">
	                                        <strong>估算工作量:</strong>[(${project.project.estimateWorkload})]人月
											<p><strong>进展情况:</strong>[(${project.project.projectSituation})]</p>
											<p><strong>紧急待办:</strong><span th:id="'P'+${project.project.projectId}">[(${project.project.urgentDescribe})]</span></p>
											<script>if($("#P[[${project.project.projectId}]]").html().length>5) urgentDescribe[urgentDescribe.length] = {title:'[(${project.project.projectName})]',urgentDescribe:$("#P[[${project.project.projectId}]]").html()};</script>
											<strong>资源投入情况:</strong>
											<table width="100%" border="1" bgcolor="#000000">
											<tr bgcolor="#CCCCCC" align="center"><td>资源</td><td>投入工时</td><td>单金</td><td>合计</td></tr>
												<script>  
													$('#PC[[${project.project.projectId}]]').on('click',function(){
														oldList('[[${project.project.projectName}]]');
						                            });
												   var workSum = 0; var moneySum = 0;
													projectWork = [(${project.work == null}?[]:${project.work})];
													$.each(projectWork, function(index, dict) {
			 
														document.write('<tr bgcolor="#FFFFFF"><td>'+dict.createBy+'</td><td align="right">'+dict.workTime+'小时'+'</td>');;

														if(dict.workContent!=0){
															document.write('<td align="right">'+dict.workContent+'元'+'</td><td align="right">'+(dict.workTime*dict.workContent)+'元</td>');
														}else{
															document.write('<td>&nbsp;</td><td>&nbsp;</td>');
														}
														document.write('</tr>');
														workSum = workSum+dict.workTime;
														moneySum = moneySum+(dict.workTime*dict.workContent)
													});
													
												</script> 
												<tr bgcolor="#FFFFFF" ><td><strong>合计：</strong></td><td align="right"><script>document.write(workSum)</script>小时</td><td>&nbsp;</td><td align="right"><script>document.write(moneySum)</script>元</td></tr>
											</table>
	                                    </div>
	                             </div>
                            </div>
                        </div>
                        <div id="tab-2" class="tab-pane">
                            <div class="panel-body">
                              <strong>支出:<span id="zhichu"></span>元； 预支出:<span id="nzhichu"></span></strong>
	                            <div class="col-sm-4">
	                                                                                    
	                                <div class="panel panel-primary" th:each="comCost : ${@comcost.getComCostList()}">
	                                    <div class="panel-heading"> 费用归属：<strong>
                                          <script>
                                           showObjectLabel(projectLists,[(${comCost.costPro})],'projectId','projectName');
                                           if( [(${comCost.costState})] == 1){
                                        	   nzhichu = nzhichu + [(${comCost.costMoney})]; 
                                        	}else{
                                        	   zhichu = zhichu + [(${comCost.costMoney})]; 
                                           }
                                          </script>
                                          </strong>
                                        </div>
	                                    <div class="panel-body">
	                                        <p><strong>类型：</strong><script> showObjectLabel(costType,'[(${comCost.costType})]','dictValue','dictLabel');</script></p>
	                                        <p><strong>消费日期：</strong>[[${#dates.format(comCost.costTime, 'yyyy-MM-dd')}]]</p>
	                                        <p><strong>金额：</strong>[(${comCost.costMoney})]元</p>
	                                        <p><strong>状态：</strong><script>showObjectLabel(costState,'[(${comCost.costState})]','dictValue','dictLabel');</script></p>
	                                        <p>[[${comCost.costRemark}]]</p>
	                                    </div>
	                                </div>
	                            </div>
                            </div>
                        </div>
                        <div id="tab-3" class="tab-pane">
                            <div class="panel-body">
	                            <div class="col-sm-4">
	                                <div class="panel panel-primary" th:each="comaffair : ${@comaffair.getComaffairList()}">
	                                    <div class="panel-heading"> <strong>[(${comaffair.affair})]</strong>
                                        </div>
	                                    <div class="panel-body">
	                                        <p><strong>工作内容：</strong>[(${comaffair.affairDescribe})]</p>
	                                        <p><strong>实际进度：</strong>[(${comaffair.actualDescribe})]</p>
	                                        <p><strong>紧急待办：</strong><span th:id="'C'+${comaffair.affairId}">[(${comaffair.urgentDescribe})]</span></p>
	                                        <script>if($("#C[[${comaffair.affairId}]]").html().length>5) urgentDescribe[urgentDescribe.length] = {title:'[(${comaffair.affair})]',urgentDescribe:$("#C[[${comaffair.affairId}]]").html()};</script>
	                                        <p><strong>计划办结时间：</strong>[[${#dates.format(comaffair.planEndTime, 'yyyy-MM-dd')}]]</p>
	                                        <p><strong>状态：</strong><script>showObjectLabel(affairFlag,'[(${comaffair.affairFlag})]','dictValue','dictLabel');</script></p> 
	                                    </div>
	                                </div>
	                            </div>
                            </div>
                        </div>
                        <div id="tab-4" class="tab-pane">
                            <div class="panel-body">
	                            <div class="col-sm-4">
	                               <form id="form-table-add" style="margin-bottom:20px;border-top: 1px solid #e7eaec;border-bottom: 1px solid #e7eaec;">
		                                <div class="panel panel-primary">
		                                    <div class="panel-body">
		                                    	<p>标题：<input name="approvalTitle" id="approvalTitle" class="form-control" type="text" required /></p>
		                                        <p>批示：</p>
		                                        <p><textarea name="approvalContent" id="approvalContent" class="form-control" required></textarea></p>
		                                        <p><button onclick="submitHandler()" class="btn btn-primary btn-lg btn-block" type="button" style="background:rgb(65,139,202);border-color:rgb(65,139,202);">提交</button></p>                                        
		                                    </div>
		                                </div>
	                                 </form>
	                                 <div id='approvalHtml'></div>
	                            </div>
                            </div>
                            
                            <script>
                            var prefix = ctx + "approval";
                            $('#urgentDescribe').on('click',function(){
                            	layer.open({
                            		type: 1,
                            		title: '紧急待办',
                            		area: ['90%', '90%'],
                            		content: $('#popup')
                            	});
                            });

                            function submitHandler() {
                                if ($.validate.form()) {
                                    $.operate.saveTab(prefix + "/add", $('#form-table-add').serialize(),function(result){
                                    	getList(); 
                                    	$.modal.closeLoading();
                                    	$("#approvalTitle").val('');
                                    	$("#approvalContent").val('');
                                    	return;
                                    });
                                }
                            }
                            function getList(){
                            	var config = {
                            	        url: prefix + "/getList",
                            	        type: "post",
                            	        dataType: "json",
                            	        success: function(result) {
                            	        	var spanHtml = "";   
                            	        	for(var i=0;i< result.length;i++){
                            	        		spanHtml = spanHtml+'<div class="panel panel-primary" >';
                            	        		spanHtml = spanHtml+'<div class="panel-heading"><strong>'+result[i].approvalTitle+'</strong><i class="glyphicon glyphicon-trash" onclick="remove(\''+result[i].approvalTitle+'\','+result[i].approvalId+')" style="float: right;"></i></div>';
                            	        		spanHtml = spanHtml+'<div class="panel-body"><p>'+result[i].approvalContent+'</p>';
                            	        		spanHtml = spanHtml+'<strong>办理进度：</strong>'+(result[i].approvalProgress==null?'':result[i].approvalProgress)+'</div>';
                            	        		spanHtml = spanHtml+'</div>';
                            	        	}
                            	        	 $("#approvalHtml").html(spanHtml);
                            	        }
                            	    };
                            	$.ajax(config)
                            }
                            
                            getList();
                            
                            function remove(modalName,id) {
                            	$.modal.confirm("确定删除 <strong>" + modalName + "</strong> 这条信息吗？", function() {
                            		var config = {
                                	        url: prefix + "/remove",
                                	        type: "post",
                                	        dataType: "json",
                                	        data:{ "ids": id },
                                	        success: function(result) {
                                	        	getList(); 
                                	        }
                                	    };
                                	$.ajax(config)
                            	});
                            	
                            }
                            $("#nzhichu").html(nzhichu);
                            $("#zhichu").html(zhichu);
                            $("#urgentDescribe").html(urgentDescribe.length);
                            var urgentDescribeList = "";   
            	        	for(var i=0;i< urgentDescribe.length;i++){
            	        		urgentDescribeList = urgentDescribeList+'<div class="panel panel-primary" >';
            	        		urgentDescribeList = urgentDescribeList+'<div class="panel-heading"><strong>'+urgentDescribe[i].title+'</strong></div>';
            	        		urgentDescribeList = urgentDescribeList+'<div class="panel-body" style="padding: 20px;">'+urgentDescribe[i].urgentDescribe+'</div>';
            	        		urgentDescribeList = urgentDescribeList+'</div>';
            	        	}
							urgentDescribeList = urgentDescribeList+"<br>"
            	        	$("#urgentDescribeList").html(urgentDescribeList);
                            </script>
                        </div>
                    </div>
                </div>
            </div>
         </div>
    </div>
</body>
</html>